home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / cursive.zip / CURSIVE.C < prev    next >
Text File  |  1987-11-25  |  9KB  |  315 lines

  1. /*      CURSIVE SIGNATURE PROGRAM       Version 0.10
  2.  *              (c) 1985 - Jan Wolter
  3.  *
  4.  *  Purpose:    This program translates text into crude cursive script.
  5.  *      It works on any terminal with a fairly normal character
  6.  *      set (must have backslashes and underscores and suchlike).
  7.  *      The font includes all upper and lower case letters, most
  8.  *      punctuation, and a few symbols.  No numbers are included
  9.  *      (It's difficult to make a nice italicized set of numbers).
  10.  *      Cursive was originally written to generate fancy signatures
  11.  *      for electronic mail messages, but other uses may occur to
  12.  *      you.  The attractiveness of the font varies greatly with
  13.  *      the display device.
  14.  *
  15.  *  Usage:  If no command line arguments are given, cursive reads the
  16.  *      text to translate from standard input.  Otherwise the args
  17.  *      are translated (e.g. "cursive Jan Wolter" prints my name).
  18.  *      Output is always to standard output.  A couple command line
  19.  *      arguments are recognized:
  20.  *
  21.  *        -in   Sets the amount of space to insert between letters.
  22.  *          The default is "-i1".  "-i0" gives interesting
  23.  *          results.
  24.  *        -tn   Sets the length of the trailing line off the end
  25.  *          of each word.  The default is "-t1".
  26.  *
  27.  *      One character in the text is treated in a special way:
  28.  *
  29.  *        '_'   Can be inserted in text to slightly lengthen the
  30.  *          the spacing between two letters, or add a longer
  31.  *          tail to the end of a word.
  32.  *
  33.  *  Internals:  Unfortunately, the program is a kludge and the font is
  34.  *      somewhat difficult to edit.  It should be easy to port
  35.  *      though.  Systems with short integers or unsigned characters
  36.  *      should be no problem.  You should probably run "xstr" on the
  37.  *      font.c file, but if you haven't got "xstr", just compiling it
  38.  *      the usual way works fine.
  39.  *
  40.  *  Copyright:  Both the cursive program and the font it generates are
  41.  *      copyrighted by yours truly.  However, both may be used
  42.  *      and distributed freely.  You even have my permission to
  43.  *      sell it, or include in it a system that you sell.  I only
  44.  *      ask that my name be retained on this program, or any direct
  45.  *      decendents of this program with approximately the same
  46.  *      visibility as in this posting.
  47.  *
  48.  *  Mail:   I'm interested in any comments you have on this program.
  49.  *      I can be mailed at "janc@crim.eecs.umich.edu".  Better yet,
  50.  *      if you are into teleconferencing, call M-Net at (313) 994-6333
  51.  *      and type "newuser" at the "login:" prompt to give yourself an
  52.  *      account.  Send mail to janc, or join the "ugames" conference.
  53.  *
  54.  *      Have fun,
  55.  *                ___                _     __  _
  56.  *               (   >              ' )   /   // _/_
  57.  *                __/___.  ____      / / / __|/  /  _  __
  58.  *               / / (_/|_/ / <__   (_(_/ (_) \_<__</_/ (__
  59.  *              <_/
  60.  */
  61.  
  62. #include "a:stdio.h"
  63. #include "cursive.h"
  64.  
  65. char *buffer[6];    /* memory buffers to build up line in */
  66. int c[6];       /* current index in each of the buffer lines */
  67. int tail[6];        /* which buffer lines have tails in them */
  68. int lasttail;       /* which line was the last letter's tail */
  69. int space;      /* how much white space before the next letter */
  70. int interspace = 1; /* how much to spread adjacent letters out */
  71. int taillen = 1;    /* how long the tails on ends of words should be */
  72. char firstletter;   /* is this the first letter on the line? */
  73. char message[256] = ""; /* message to print */
  74.  
  75. char *malloc();
  76.  
  77. /* These are used by atoi */
  78.  
  79. #define TAB             '\t'
  80. #define SP              ' '
  81. #define PLUS            '+'
  82. #define MINUS           '-'     /* Redundant, but clearer */
  83. #define LEASTN          '0'
  84. #define MOSTN           '9'
  85.  
  86.  
  87. main(argc,argv)
  88. int argc;
  89. char **argv;
  90. {
  91. int i;
  92. char *s,*m;
  93. char ch;
  94.  
  95.     m = message;
  96.     for (i = 1; i < argc; i++)
  97.     {
  98.         if (*argv[i] == '-')
  99.             switch(ch = argv[i][1])
  100.             {
  101.             case 'i':
  102.             case 't':
  103.                 s = argv[i]+2;
  104.                 if (*s == '\000')
  105.                     if (++i < argc)
  106.                         s = argv[i];
  107.                 if (*s < '0' || *s > '9')
  108.                 {
  109.                     printf("%s: Illegal value %s\n",
  110.                         argv[0],s);
  111.                     exit(1);
  112.                 }
  113.                 if (ch == 'i')
  114.                     interspace = atoi(s);
  115.                 else
  116.                     taillen = atoi(s);
  117.                 break;
  118.             default:
  119.                 printf("usage: %s [-tn] [-in] message\n",
  120.                     argv[0]);
  121.                 exit(1);
  122.             }
  123.         else
  124.         {
  125.             if (m != message)
  126.                 *(m++) = ' ';
  127.             for (s=argv[i]; *s != '\000'; s++)
  128.                 *(m++) = *s;
  129.         }
  130.     }
  131.     /* Do the deed */
  132.     if (m != message)
  133.     {
  134.         /* Message from the arg list */
  135.         *(m++) = 0;
  136.         prline(message);
  137.     }
  138.     else
  139.     {
  140.         /* Message from standard input */
  141.         while (gets(message) != NULL)
  142.             prline(message);
  143.     }
  144. }
  145.  
  146.  
  147. /* Add the given letter to the end of the current line */
  148.  
  149. place(let)
  150. struct letter *let;
  151. {
  152. int i,j,n;
  153. int col;
  154. int maxx= -10000;
  155. char pad;
  156. char *l;
  157.  
  158.     if (firstletter)
  159.     {
  160.         col = space;        /* Leading spaces */
  161.         firstletter = 0;
  162.     }
  163.     else
  164.     {
  165.         /* Find the furthest left position we can place this letter */
  166.         for(i=0; i<6; i++)
  167.         {
  168.             if (let->line[i][0] != '\000' &&
  169.                 (col = c[i] - let->spcs[i]) > maxx)
  170.                 maxx = col;
  171.         }
  172.  
  173.         /* Insert some spaces between letters */
  174.         col = maxx + space + interspace;
  175.     }
  176.  
  177.     for(i=0; i<6; i++)
  178.  
  179.         /* If Nothing on this Line, Skip It */
  180.         if (let->line[i][0] != '\000')
  181.         {
  182.             /* Number of Spaces to Put on this Line? */
  183.             n = col - c[i] + let->spcs[i];
  184.  
  185.             /* Flyers off Ends of Letters */
  186.             if (tail[i])
  187.                 for (j = 0;
  188.                      j < 5 && n > space + 2; j++,n--)
  189.                     buffer[i][c[i]++] = '_';
  190.  
  191.             /* Connecting Lines Between Letters */
  192.             pad = (lasttail == i && let->tailin == i) ? '_' : ' ';
  193.  
  194.             /* In the middle of the intersection of South and */
  195.             /* East University, someone is playing the piano. */
  196.             for ( ; n > 0; n--)
  197.                 buffer[i][c[i]++] = pad;
  198.  
  199.             /* Copy in the letter text */
  200.             for (l = let->line[i]; *l != '\000'; l++)
  201.                 buffer[i][c[i]++] = *l;
  202.  
  203.             tail[i] = (i == let->tailout);
  204.         }
  205.  
  206.     lasttail = let->tailout;
  207.     space = 0;
  208. }
  209.  
  210. /* Lengthen the last trailer by n */
  211. tailer(n)
  212. int n;
  213. {
  214. int j;
  215.     if (lasttail >= 0)
  216.         for (j = 0; j < n; j++)
  217.             buffer[lasttail][c[lasttail]++] = '_';
  218. }
  219.  
  220. /* Handle a line */
  221. prline(s)
  222. char *s;
  223. {
  224. int l,i;
  225. char *ch;
  226. short lcode;
  227.  
  228.     lasttail = -1;
  229.     firstletter = 1;
  230.     space = 0;
  231.     /* Get some memory to put the output into */
  232.     l = strlen(s) * (CHARWIDTH + interspace);
  233.     for (i=0;i<6;i++)
  234.     {
  235.         buffer[i] = malloc((unsigned)l);
  236.         tail[i] = c[i] = 0;
  237.     }
  238.  
  239.     /* do each letter */
  240.     for (ch=s; *ch != '\000'; ch++)
  241.     {
  242.  
  243.         *ch &= '\177';
  244.         /* Find the letter */
  245.         lcode = (lasttail != 2) ? code1[*ch] : code2[*ch];
  246.         if (lcode >= 0)
  247.             place(&list[lcode]);
  248.         else
  249.             /* Various Special characters */
  250.             switch(lcode)
  251.             {
  252.             case SP:
  253.                 /* Insert white space before next letter */
  254.                 tailer(taillen);
  255.                 space += 3;
  256.                 lasttail = -1;
  257.                 break;
  258.             case ST:
  259.                 /* Lengthen the last tail */
  260.                 if (lasttail >= 0)
  261.                     buffer[lasttail][c[lasttail]++] = '_';
  262.                 break;
  263.             }
  264.     }
  265.     tailer(taillen);
  266.  
  267.     /* print the line and release the memory */
  268.     for (i=0;i<6;i++)
  269.     {
  270.         buffer[i][c[i]++] = '\n';
  271.         write(1,buffer[i],c[i]);
  272.         free(buffer[i]);
  273.     }
  274. }
  275.  
  276. /*
  277. **      atoi
  278. **
  279. **      Convert an ASCII string to an integer
  280. **
  281. */
  282.  
  283.  
  284. int atoi( ap )
  285. char *ap;
  286. {
  287.         register int n, c;
  288.         register char *p;
  289.         int f;
  290.  
  291.         p = ap;
  292.         n = 0;
  293.         f = 1;
  294.  
  295.         /* Scan the string for spaces or signs */
  296.         for( ; ;p++ ){
  297.                 if( *p == SP || *p == TAB || *p == PLUS )
  298.                         continue;
  299.                 if( *p == MINUS ){
  300.                         f = -f;
  301.                         continue;
  302.                 }
  303.                 break;
  304.         }
  305.  
  306.         /* Now assemble the number */
  307.         while( *p >= LEASTN && *p <= MOSTN )
  308.                 n = n*10 + *p++ - LEASTN;
  309.         if( f < 0 )
  310.                 n = -n;
  311.  
  312.         return( n );
  313. }
  314.  
  315.